var Yiyonghaocai = new Vue({
    el : "#Yiyonghaocailist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmuleixing: "",
        xiangmu : {},
        yiyonghaocai :{},
        yiyonghaocailist : [],
        show : false,					// 显示列表是否有数据

        pageIndex : 1,
        pageSize :9999,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindYiyonghaocaiList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuleixing = data.xiangmuleixing;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toDelete:function (){
            var _this = this;

            layer.confirm("确定删除该项目的材料吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/hc45/delete", {
                    xiangmuid : _this.xiangmuId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"删除成功!",
                            });

                            _this.bindYiyonghaocaiList();
                            _this.bindXiangmu();
                        }
                    }
                },"json");
            })
        },

        bindYiyonghaocaiList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/hc45/findhc45list",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >引进类型</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >总序号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >品种名</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >品牌序号</th>\n";
                            mmHtml +=
                            "       <th style=\"text-align:center;vertical-align:middle;\" >平台编码</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >产品名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >规格</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >型号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >注册证号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >品牌名</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >单位</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >单价</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >医保编码</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >国产/进口</th>\n";
                        mmHtml += "    </thead>";
                        if(data.Hc45List.length > 0){
                            _this.show = true;
                            _this.yiyonghaocailist = data.ShijiList;

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.Hc45List.length; i++) {
                                var mmYiyonghaocai = data.Hc45List[i];
                                var mmYinjinleixing = mmYiyonghaocai.yinjinleixing;
                                var mmPinzhong = mmYiyonghaocai.pinzhongxuhao;
                                var mmPinzhongming = mmYiyonghaocai.pinzhongming;
                                var mmPinpaiList = mmYiyonghaocai.pinpailist;
                                var mmPinzhongHebingshu = mmYiyonghaocai.pinzhonghebinghang;

                                for (var j = 0; j < mmPinpaiList.length; j++) {
                                    var s=0;

                                    var mmPinpailist = mmPinpaiList[j];
                                    var mmPinpai = mmPinpailist.pinpaixuhao;
                                    var mmXinghaolist= mmPinpailist.xinghaolist;
                                    var mmPinpaiHebingshu = mmPinpailist.pinpaihebinghang;
                                    var mmPinpaiHebinghang = "";
                                    if (mmPinpaiHebingshu > 1) {
                                        mmPinpaiHebinghang = "rowspan='" + mmPinpaiHebingshu + "'";
                                    } else {
                                        mmPinpaiHebinghang = "";
                                    }


                                    for (var k = 0; k < mmXinghaolist.length; k++) {
                                        var mmxinghaolist = mmXinghaolist[k];
                                        var mmOrdernumber = mmxinghaolist.ordernumber;
                                        // var mmleibie = mmxinghaolist.leibie;
                                        var mmWuzibianma = mmxinghaolist.wuzibianma;
                                        var mmPingtaibianma = mmxinghaolist.pingtaibianma;
                                        var mmChanpinmingcheng = mmxinghaolist.chanpinmingcheng;
                                        var mmGuige = mmxinghaolist.guige;
                                        var mmXinghao = mmxinghaolist.xinghao;
                                        var mmZhucezhenghao = mmxinghaolist.zhucezheng;
                                        var mmPinpaiming = mmxinghaolist.pinpaiming;
                                        var mmShengchanshang = mmxinghaolist.shengchanchangjia;
                                        var mmJijiadanwei = mmxinghaolist.danwei;
                                        var mmPingtaidanjia = mmxinghaolist.danjia;
                                        var mmYibaobianma = mmxinghaolist.yibaobianma;
                                        var mmJinkouguochan = mmxinghaolist.guochanjinkou;
                                        var mmLiyou = mmxinghaolist.liyou;
                                        var mmBeizhu = mmxinghaolist.beizhu;
                                        var mmHuanhangfu = "";
                                        var mmerjihe="";
                                        var mmyijihe="";
                                        if (k != 0) {
                                            mmHuanhangfu = "<tr>";
                                        }else{
                                            mmerjihe="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + mmPinpai + "</td>";
                                        }
                                        if(j === 0 && s === 0){
                                            mmyijihe= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmYinjinleixing + "</td>";
                                            mmyijihe+= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhong + "</td>";
                                            mmyijihe+= "<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongming + "</td>";
                                            s= 1;
                                        }

                                        mmHtml += mmHuanhangfu;


                                        mmHtml +=mmyijihe;

                                        mmHtml+=mmerjihe

                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmPingtaibianma + "'>" + mmPingtaibianma + "</a></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmChanpinmingcheng + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmXinghao + "'>" + mmXinghao + "</a></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhucezhenghao + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPinpaiming + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJijiadanwei + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmPingtaidanjia + "</td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmYibaobianma + "'>" + mmYibaobianma + "</a></td>";
                                        mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJinkouguochan + "</td>";
                                        mmHtml += "</tr>";
                                    }
                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindYiyonghaocaiList();
        }
    }
});
